package com.xgkj.diyiketang.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ExpandableListView;
import android.widget.TextView;
import android.widget.Toast;

import com.xgkj.diyiketang.R;
import com.xgkj.diyiketang.activity.data.ExpandableListAdapter;
import com.xgkj.diyiketang.util.Model;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class TuiJianTitle extends BaseActivity {
    private static final String TAG = "TuiJianTitle";
    private TextView back;
    private ExpandableListView expandableListView;
    private ExpandableListAdapter adapter;

    private List<Map<String, Object>> list;
    private String[][] child_text_array;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_tui_jian_title);
        back = (TextView) findViewById(R.id.back);
        expandableListView = (ExpandableListView) findViewById(R.id.list);
        back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        init();
        initModle();
        setListener();
    }


    private void init() {
        expandableListView = (ExpandableListView) findViewById(R.id.list);

        child_text_array = Model.EXPANDABLE_MORELIST_TXT;
    }

    private void setListener() {
        expandableListView.setOnGroupClickListener(new ExpandableListView.OnGroupClickListener() {

            @Override
            public boolean onGroupClick(ExpandableListView parent, View v, int groupPosition, long id) {
                return false;
            }
        });

        expandableListView.setOnChildClickListener(new ExpandableListView.OnChildClickListener() {

            @Override
            public boolean onChildClick(ExpandableListView parent, View v,
                                        int groupPosition, int childPosition, long id) {
                Intent intent = new Intent(TuiJianTitle.this, YuZhiBoActivity.class);
                Bundle bundle = new Bundle();
                bundle.putString("TITLE", child_text_array[groupPosition][childPosition]);
                intent.putExtra("bundle", bundle);
             //   setResult(YuZhiBoActivity.RESULT_CODE_TITLE, intent);
                finish();
                return false;
            }
        });
    }

    private void initModle() {
        list = new ArrayList<Map<String, Object>>();
        for (int i = 0; i < Model.EXPANDABLE_LISTVIEW_TXT.length; i++) {
            Map<String, Object> map = new HashMap<String, Object>();
            map.put("img", Model.EXPANDABLE_LISTVIEW_IMG[i]);
            map.put("txt", Model.EXPANDABLE_LISTVIEW_TXT[i]);
            list.add(map);
        }
        adapter = new ExpandableListAdapter(this, list, child_text_array);
        expandableListView.setAdapter(adapter);
    }
}
